home *** CD-ROM | disk | FTP | other *** search
/ How to Get Online 1996 Spring / HOW2GON.ISO / mac / Servers & CGI / CmmCGI / HTML.LIB < prev    next >
Encoding:
Text File  |  1996-02-07  |  7.2 KB  |  283 lines  |  [TEXT/ttxt]

  1. //
  2. // html.lib
  3. //
  4. //   This is a library for outputing forms from CGI scripts using CMMCGI.
  5. //   
  6. //   These routines make form output a breeze. You end up with code that
  7. //   looks like the form it will generate using these style guidelines.
  8. // 
  9. //   CGIOUT(
  10. //      HTML(
  11. //         HEAD(
  12. //            TITLE("This is the title for a form")
  13. //         ),
  14. //         BODY(
  15. //            H2("This is the body for a form")
  16. //         )
  17. //      )
  18. //   )
  19. //   
  20. //   The above is a series of function calls all returning strings 
  21. //   that results in a form being built. CGIOUT takes care of returning 
  22. //   the form over the CGI interface on the system the script is run on.
  23. //
  24. //   Don't forget to add the appropriate number of commas in between
  25. //   function arguments. 
  26. // ----------------------------------------------------------------------
  27.  
  28. // This is like a sprintf, except it returns a string containing the result.
  29. // for example: retPrintf("%s %d %s",string1, int1, string2);
  30. retPrintf(FormatString/*,args*/)
  31. {
  32.    va_start(VaList,FormatString);
  33.    vsprintf(RetStr,FormatString,VaList);
  34.    va_end(VaList);
  35.    return RetStr;
  36. }
  37.  
  38. // Take all the command line args and append them together in one string
  39. ArgAppend(ArgCount,VaList,SkipCount)
  40. {
  41.    RetStr = "";
  42.    for ( ArgIdx = SkipCount; ArgIdx < ArgCount; ArgIdx++ )
  43.       strcat(RetStr,va_arg(VaList,ArgIdx));
  44.  
  45.    va_end(VaList);
  46.    return RetStr;
  47. }
  48.  
  49. // some convienient defines for calling arg append
  50. #define APPEND_ALL     ArgAppend(va_start(VaList),VaList,0)
  51. #define APPEND_ALL_1   ArgAppend(va_start(VaList),VaList,1)
  52. #define APPEND_ALL_2   ArgAppend(va_start(VaList),VaList,2)
  53.  
  54. // defines for the HTML tags that don't require end tags
  55. #define LINEBREAK   "<BR>"
  56. #define BR          "<BR>"
  57. #define HR          "<HR>"
  58. #define ISINDEX     "<ISINDEX>"
  59. #define P           "<P>"
  60. #define ENDP        "</P>"
  61.  
  62. // The HTML tag functions starthere. We included all HTML 2.0
  63. // tags. Where there are many possible attributes, you need 
  64. // to fill them in yourself. If you improve this library, please
  65. // send it to Nombas. If you have HTML questions, look at html2_0.doc
  66.  
  67. // ANCHOR - requires href, and attr. If you don't need any attributes make
  68. // sure to put a null string - ""
  69. ANCHOR(hRef,attr)
  70. {
  71.    return strcat(retPrintf("<A HREF=\"%s\" %s>",hRef,attr),APPEND_ALL_2,"</A>");
  72. }
  73. // Address - appends all parameters between the tags
  74. ADDRESS()
  75. {
  76.    return strcat("<ADDRESS>",APPEND_ALL,"</ADDRESS>\n");
  77. }
  78. // Bold - appends all parameters between the tags
  79. B()
  80. {
  81.    return strcat("<B>",APPEND_ALL,"</B>\n");
  82. }
  83. // Base - requires the href to be used for the base of this html doc 
  84. BASE(href)
  85. {
  86.    return strcat(`<BASE HREF="`,href,`">`);
  87. }
  88. // Blockquote - appends all parameters between the tags
  89. BLOCKQUOTE()
  90. {
  91.    return strcat("<BLOCKQUOTE>",APPEND_ALL,"</BLOCKQUOTE>\n");
  92. }
  93. // Body - appends all parameters between the tags
  94. BODY()
  95. {
  96.    return strcat("<BODY>",APPEND_ALL,"</BODY>\n");
  97. }
  98. // Bodytext - appends all parameters between the tags
  99. BODYTEXT()
  100. {
  101.    return strcat("<BODYTEXT>",APPEND_ALL,"</BODYTEXT>\n");
  102. }
  103. // Cite - appends all parameters between the tags
  104. CITE()
  105. {
  106.    return strcat("<CITE>\n",APPEND_ALL,"\n<CITE/>\n");
  107. }
  108. // Code - appends all parameters between the tags
  109. CODE()
  110. {
  111.    return strcat("<CODE>",APPEND_ALL,"</CODE>\n");
  112. }
  113. // DD - appends all parameters after the tag
  114. DD()
  115. {
  116.    return strcat("<DD>",APPEND_ALL);
  117. }
  118. // DIR - appends all parameters between the tags
  119. DIR()
  120. {
  121.    return strcat("<DIR>\n",APPEND_ALL,"\n</DIR>\n");
  122. }
  123. // DL - appends all parameters between the tags
  124. DL()
  125. {
  126.    return strcat("<DL>\n",APPEND_ALL,"</DL>\n");
  127. }
  128. // DT - appends all parameters after the tag
  129. DT()
  130. {
  131.    return strcat("<DT>",APPEND_ALL);
  132. }
  133. // EM - appends all parameters between the tags
  134. EM()
  135. {
  136.    return strcat("<EM>",APPEND_ALL,"</EM>\n");
  137. }
  138. // Bold - appends all parameters between the tags and adds the attributes
  139. //        in the FORM tag
  140. FORM(attr)
  141. {
  142.    return strcat(retPrintf("<FORM %s>",attr),APPEND_ALL_1,"</FORM>");
  143. }
  144. // Head - appends all parameters between the tags
  145. HEAD()
  146. {
  147.    return strcat("<HEAD>",APPEND_ALL,"</HEAD>\n");
  148. }
  149. // Heading - appends all parameters between the tags to the appropriate
  150. //           H-level ie H1, H2, ...
  151. HEADING(Level)
  152. {
  153.    return strcat(retPrintf("<H%d>",Level),APPEND_ALL_1,retPrintf("</H%d>",Level));
  154. }
  155. // H1-H6 - appends all parameters between the tags
  156. H1()
  157. {
  158.    return strcat("<H1>",APPEND_ALL,"</H1>\n");
  159. }
  160. H2()
  161. {
  162.    return strcat("<H2>",APPEND_ALL,"</H2>\n");
  163. }
  164. H3()
  165. {
  166.    return strcat("<H3>",APPEND_ALL,"</H3>\n");
  167. }
  168. H4()
  169. {
  170.    return strcat("<H4>",APPEND_ALL,"</H4>\n");
  171. }
  172. H5()
  173. {
  174.    return strcat("<H5>",APPEND_ALL,"</H5>\n");
  175. }
  176. H6()
  177. {
  178.    return strcat("<H6>",APPEND_ALL,"</H6>\n");
  179. }
  180. // HTML - appends all parameters between the tags and adds the attributes
  181. //        to the HTML tag. If there are no attributes, use a null string ""
  182. HTML(attr)
  183. {
  184.    if (defined(_MAC_))
  185.       return strcat(retPrintf("<HTML %s>",attr),APPEND_ALL_1,"</HTML>");
  186.    else
  187.       return strcat(retPrintf(
  188.         "Content-Type: text/html\n\n\n<HTML %s>",attr),APPEND_ALL_1,"</HTML>");
  189. }
  190. // Italicize - appends all parameters between the tags
  191. I()
  192. {
  193.    return strcat("<I>\n",APPEND_ALL,"</I>\n");
  194. }
  195. // Image - appends all parameters between the tagsas image attributes and
  196. //         sets the image URL
  197. IMG(image)
  198. {
  199.    return strcat(retPrintf("<IMG SRC=\"%s\" ",image),APPEND_ALL_1,">\n");
  200. }
  201. // Input - appends all parameters between the tags as input attributes and
  202. //         sets the input to the type specified
  203. INPUT(type)
  204. {
  205.    return strcat(retPrintf("<INPUT TYPE=%s ",type),APPEND_ALL_1,">\n");
  206. }
  207. // KBD - appends all parameters between the tags
  208. KBD()
  209. {
  210.    return strcat("<KBD>",APPEND_ALL,"</KBD>\n");
  211. }
  212. // List Item - appends all parameters after the list item tag
  213. LI()
  214. {
  215.    return strcat("<LI>",APPEND_ALL);
  216. }
  217. // Link - appends all parameters between the tags
  218. LINK(attr)
  219. {
  220.    return retPrintf("<LINK %s>",attr);
  221. }
  222. // Menu - appends all parameters between the tags should be menu items
  223. MENU()
  224. {
  225.    return strcat("<MENU>\n",APPEND_ALL,"</MENU>\n");
  226. }
  227. // OL - appends all parameters between the tags should be list items
  228. OL()
  229. {
  230.    return strcat("<OL>\n",APPEND_ALL,"</OL>\n");
  231. }
  232. // OPTION - set the option attributes and appends other parameters after
  233. OPTION(attr)
  234. {
  235.    return strcat(retPrintf("<OPTION %s>",attr),APPEND_ALL_1,"\n");
  236. }
  237. // Preformatted - appends all parameters between the tags 
  238. PRE()
  239. {
  240.    return strcat("<PRE>\n",APPEND_ALL,"</PRE>\n");
  241. }
  242. // Sample - appends all parameters between the tags
  243. SAMP()
  244. {
  245.    return strcat("<SAMP>",APPEND_ALL,"</SAMP>\n");
  246. }
  247. // Select - appends all parameters between the tags
  248. SELECT()
  249. {
  250.    return strcat("<SELECT>\n",APPEND_ALL,"</SELECT>\n");
  251. }
  252. // Strong - appends all parameters between the tags
  253. STRONG()
  254. {
  255.    return strcat("<STRONG>",APPEND_ALL,"</STRONG>\n");
  256. }
  257. // Text Area - sets the attributes
  258. TEXTAREA(attr)
  259. {
  260.    return retPrintf("<TEXTAREA %s>\n",attr);
  261. }
  262. // Title - appends all parameters between the tags
  263. TITLE()
  264. {
  265.    return strcat("<TITLE>",APPEND_ALL,"</TITLE>\n");
  266. }
  267. // TT - appends all parameters between the tags
  268. TT()
  269. {
  270.    return strcat("<TT>",APPEND_ALL,"</TT>\n");
  271. }
  272. // Unnumbered list - appends all parameters between the tags 
  273. //                   should be list items
  274. UL()
  275. {
  276.    return strcat("<UL>\n",APPEND_ALL,"</UL>\n");
  277. }
  278. // Variable - appends all parameters between the tags as variable text
  279. VAR()
  280. {
  281.    return strcat("<VAR>",APPEND_ALL,"</VAR>\n");
  282. }
  283.